import React from "react";
import { Radio } from "antd";
import "./index.less";

interface IVRadioOption {
  label: string;
  value: any;
}
interface IVRadioProps {
  options: Array<IVRadioOption>;
  type?: "default" | "button";
  [key: string]: any;
}
class VRadio extends React.Component<IVRadioProps> {
  handleChange = (ev) => {
    const { onChange } = this.props;
    onChange && onChange(ev.target.value)
  }
  render() {
    const { type, options } = this.props;
    return type === "button" ? <Radio.Group buttonStyle="solid" onChange={this.handleChange} defaultValue={this.props.default}>
      {options.map(op => <Radio.Button key={op.value} value={op.value} className="visbar-gui-radio-btn">{ op.label }</Radio.Button>) }
    </Radio.Group> : <Radio.Group name={this.props.key} {...this.props} onChange={this.handleChange} defaultValue={this.props.default}></Radio.Group>
  }
}

export default VRadio;